package com.qidian.blog.servlet;

import com.qidian.blog.factory.ServiceFactory;
import com.qidian.blog.service.ImageService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author 郭浩
 * @Date 2022/10/11 15:15
 */
@WebServlet("/image")
public class ImageServlet extends BaseServlet{
    private ImageService imageService = ServiceFactory.getService(ImageService.class);
    public void list(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        int page = 1;
        int limit = 10;
        try{page = new Integer(req.getParameter("page"));}catch (NumberFormatException e){}
        try{limit = new Integer(req.getParameter("limit"));}catch (NumberFormatException e){}
        respJson(imageService.queryByPage(page,limit),resp);
    }
    public void delete(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        String fileName = req.getParameter("fileName");
        respJson(imageService.delete(fileName),resp);
    }
}
